<?php

declare(strict_types=1);
/**
 * 
 */
namespace WanZ\App\User\Logic\Traits;

use WanZ\App\User\Consumer\Sms;
use MoChat\Framework\Constants\ErrorCode;
use MoChat\Framework\Exception\CommonException;

trait SmsTrait
{
    /**
     * 通过不同类型发送验证码
     *
     * @param $phone
     * @param int $companyId
     * @param $type
     * @return bool
     * @throws ApiException
     * @throws GuzzleException
     */
    public function sendVerificationCodeByType($phone, int $companyId, $type): bool
    {
        return make(Sms::class)->_(['phone' => $phone, 'company_id' => $companyId, 'type' => $type])->sendCodeHandle();
    }

    /**
     * 短信验证码校验
     *
     * @param $phone
     * @param $type
     * @param $code
     * @return bool
     * @throws ApiException
     * @throws GuzzleException
     */
    public function verifyCodeHandle($phone, $type, $code): bool
    {
        return make(Sms::class)->_(['phone' => $phone, 'type' => $type, 'verifyCode' => $code])->verifyCode();
    }
}
